<?php

class Model_Orm_Cinema_Tests extends \PHPUnit_Framework_TestCase
{
    public static function tearDownAfterClass()
    {
 //       $auditorium_id = Model_Orm_Auditorium::query()->max('id');
 //       Model_Orm_Auditorium::find($auditorium_id)->delete();
    }
    
    public function test_cin_1() {
        $data = array(
            'Cinema_Name' => 'New CinemaIS',
            'Cinema_Address' => 'Riga street 10, Riga, Latvia',
            'Cinema_Slogan' => 'Only the best movies!'
        );

        $validation = Model_Orm_Cinema::validate('add');
        if($validation->run($data) == false) {
            throw new Orm\ValidationFailed(implode(' * ', e((array) $validation->error())));
        } else {
            $cinema_info = Model_Orm_Cinema::find('first');
            $cinema_info->name = $validation->validated('Cinema_Name');
            $cinema_info->address = $validation->validated('Cinema_Address');
            $cinema_info->slogan = $validation->validated('Cinema_Slogan');
            $cinema_info->save();
        }
    }
    
    public function test_cin_2() {
        $data = array(
            'Auditorium_Name' => '3rd auditorium',
            'Rows' => 10,
            'Seats' => 10,
            'Support_3D' => 0
        );

        $validation = Model_Orm_Auditorium::validate('add_cin_2');

        if($validation->run($data) == false) {
            throw new Orm\ValidationFailed(implode(' * ', e((array) $validation->error())));
        } else {
            $new_auditorium = new Model_Orm_Auditorium();
            $new_auditorium->auditorium_name = $validation->validated('Auditorium_Name');
            $new_auditorium->rows = $validation->validated('Rows');
            $new_auditorium->seats_per_row = $validation->validated('Seats');
            $new_auditorium->support_3d = $validation->validated('Support_3D');
            $new_auditorium->save();
        }
    }
}